import sys
sys.path.append('..\\..')
from Djoser import *


class MyApplication(DjApplication):
	sw = None
	def layout(self,window):
		window.title = 'Welcome'
		
		window.label('Let us go')
		window.button('Subwi',self.subwindow)
		window.button('Modal Dialog',self.dlg)
	def subwindow(self):
		if self.sw==None:self.sw = MySubwindow()
		else: self.sw.close()
	def dlg(self):
		dlg = MySubwindowDialog()
		dlg.run_dialog()
		print dlg.result
		#~ dlg.run_dialog() #try to use it after it was disposed?
		#~ print dlg.result
		

class MySubwindow(DjApplicationSubwindow):
	def layout(self,window):
		window.title = 'Welcome to the subwindow'
		
		def onclick(): print 'yay'
		window.button('hi',onclick)
		window.button('quit',lambda: self.close() )

class MySubwindowDialog(DjApplicationSubwindow):
	def layout(self,window):
		window.title = 'Welcome'
		
		window.button('yes',self.ok)
		window.button('no',self.cancel)
	def ok(self):
		self.result = 'yes'
		self.end_dialog()
	def cancel(self):
		self.result='no'
		self.end_dialog()

app = MyApplication()
app.run()